package com.googlecode.webduff.methods;

import java.util.Hashtable;

import javax.servlet.ServletContext;

import com.googlecode.webduff.MimeTyper;
import com.googlecode.webduff.WebDuffConfiguration;
import com.googlecode.webduff.locking.ResourceLocks;
import com.googlecode.webduff.store.WebdavStore;


@SuppressWarnings("unchecked")
public class MethodRegistry extends Hashtable<String, MethodExecutor> {

	private static final long serialVersionUID = 4283991606989796006L;

	public MethodRegistry() {
		put("OPTIONS", new DoOptions());
		put("PROPFIND", new DoPropfind());
		put("PROPPATCH", new DoNotImplemented());
		put("MKCOL", new DoMkcol());
		put("GET", new DoGet());
		put("HEAD", new DoHead());
		put("DELETE", new DoDelete());
		put("PUT", new DoPut());
		put("COPY", new DoCopy());
		put("MOVE", new DoMove());
		put("LOCK", new DoLock());
		put("UNLOCK", new DoUnlock());
		put("NOT_IMPLEMENTED", new DoNotImplemented());
	}

	public MethodExecutor getMethod(String methodName, WebDuffConfiguration servletConfig,
			MethodRegistry methodsRegistry, WebdavStore store,
			ResourceLocks resourceLocks, MimeTyper mimeTyper, ServletContext servletContext) {
		if(containsKey(methodName)) {
			get(methodName).init(servletConfig, methodsRegistry, store, resourceLocks, mimeTyper, servletContext);
			return get(methodName);
		}
		return get("NOT_IMPLEMENTED");
	}
	
}